package controllers

import (
	"bankend/services"
	"net/http"

	"github.com/gin-gonic/gin"
)

// SendOrderNotification 接收下单参数并推送模板消息
// POST /wx/order/notify
func SendOrderNotification(c *gin.Context) {
	var req struct {
		OpenID      string `json:"openid" binding:"required"`
		OrderNo     string `json:"order_no" binding:"required"`
		ServiceName string `json:"service_name" binding:"required"`
	}
	if err := c.ShouldBindJSON(&req); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	wxSvc := services.NewWxService()
	if err := wxSvc.SendOrderNotify(req.OpenID, req.OrderNo, req.ServiceName); err != nil {
		c.JSON(http.StatusInternalServerError, gin.H{"status": "fail", "message": err.Error()})
		return
	}
	c.JSON(http.StatusOK, gin.H{"status": "success"})
}
